package universityMap;

import KMLGenerator.MEStyle;
import KMLGenerator.MapEdge;
import KMLGenerator.MapVert;

/**
 * This class represents an agreement between 2 institutions; it is modeled on
 * the table Agreements into the database.
 * 
 * @author Andrea Piermarteri, Matteo Micheletti, Diego Cervellini
 * 
 */
public class Agreement {
	private int id;
	private Institution i1;
	private Institution i2;
	public String type;
	public String description;
	public int tots12;
	public int totm12;
	public int tots21;
	public int totm21;
	public String ic1;
	public String ic2;
	public MEStyle style;

	/**
	 * This method access the id of the agreement.
	 * 
	 * @return the agreement's id.
	 */
	public int getId() {
		return this.id;
	}

	/**
	 * Constructor of Agreements.
	 * 
	 * @param id
	 * @param i1
	 * @param i2
	 * @param type
	 * @param description
	 * @param tots12
	 * @param totm12
	 * @param tots21
	 * @param totm21
	 * @param ic1
	 * @param ic2
	 */
	public Agreement(int id, Institution i1, Institution i2, String type,
			String description, int tots12, int totm12, int tots21, int totm21,
			String ic1, String ic2) {
		this.id = id;
		this.i1 = i1;
		this.i2 = i2;
		this.type = type;
		if (this.type.trim().equalsIgnoreCase("double Degree")) {
			this.style = new MEStyle("doubleDegree", "64f00014", "3");
		}
		if (this.type.trim().equalsIgnoreCase("erasmus Mobility")) {
			this.style = new MEStyle("erasmus", "641400ff", "3");
		}
		if (this.type.trim().equalsIgnoreCase("international cooperation")) {
			this.style = new MEStyle("internationalCooperation", "6414f000",
					"3");
		}
		this.description = description;
		this.tots12 = tots12;
		this.totm12 = totm12;
		this.tots21 = tots21;
		this.totm21 = totm21;
		this.ic1 = ic1;
		this.ic2 = ic2;
	}

	/**
	 * Sets the first Institution.
	 * 
	 * @param i1
	 */
	public void setI1(Institution i1) {
		this.i1 = i1;
	}

	/**
	 * 
	 * @return the first Institution.
	 */
	public Institution getI1() {
		return i1;
	}

	/**
	 * Sets the second Institution.
	 * 
	 * @param i2
	 */
	public void setI2(Institution i2) {
		this.i2 = i2;
	}

	/**
	 * 
	 * @return the second Institution.
	 */
	public Institution getI2() {
		return i2;
	}

	/**
	 * This method formats the description field in order to make it contain all
	 * the information we want to display into the Google Earth Plugin; it is
	 * called by getMapEdge().
	 */
	private void normalize(String agrType) {
		String ni1, ni2;
		ni1 = this.getI1().name;
		ni2 = this.getI2().name;

		// if (agrType.trim().equalsIgnoreCase("erasmus mobility"))
		// this.description = "<i>" + ni1 + " and " + ni2
		// + "</i><br><br><br><b>" + ni1 + " &#8594 " + ni2
		// + "</b><br><br>" + "Total scholarships: " + tots12
		// + " students, " + totm12 + " months; <br><br>"
		// + "Courses offered at " + ni2 + ":" + "<br><br>" + this.ic2
		// + "<br><br><br><b>" + ni2 + " &#8594 " + ni1
		// + "</b><br><br>" + "Total scholarships " + ": " + tots21
		// + " students, " + totm21 + " months; <br><br>"
		// + "Courses offered at " + ni1 + ":" + "<br><br>" + this.ic1
		// + "<br><br>" + this.description;

		if (agrType.trim().equalsIgnoreCase("erasmus mobility"))
			this.description = "<i>" + ni1 + " and " + ni2
					+ "</i><br><br><br><b>" + ni1 + " &#8594 " + ni2
					+ "</b><br><br>" + this.ic2
					+ "<br><br>Total scholarships: " + this.tots12 + " students, "
					+ this.totm12 + " months;" + "<br><br><br><b>" + ni2
					+ " &#8594 " + ni1 + "</b><br><br>" + this.ic1
					+ "<br><br>Total scholarships: " + this.tots21 + " students, "
					+ this.totm21 + " months; <br><br>" + this.description;

		// if (agrType.trim().equalsIgnoreCase("double degree"))
		// this.description = "<i>" + ni1 + " and " + ni2
		// + "</i><br><br><br><b>" + ni1 + " &#8594 " + ni2
		// + "</b><br><br>" + "Total scholarships: " + tots12
		// + " students, " + totm12 + " months; <br><br>" + this.ic1
		// + "<br><br><br><b>" + ni2 + " &#8594 " + ni1
		// + "</b><br><br>" + "Total scholarships " + ": " + tots21
		// + " students, " + totm21 + " months; <br><br>" + this.ic2
		// + "<br><br>" + this.description;

		if (agrType.trim().equalsIgnoreCase("double degree"))
			this.description = "<i>" + ni1 + " and " + ni2
					+ "</i><br><br><br>" + this.ic1 + "<br><br>" + ni1
					+ " &#8594 " + ni2 + "<br><br>Total scholarships: " + this.tots12
					+ "students, 12 months" + this.description;

		if (agrType.trim().equalsIgnoreCase("international cooperation"))
			this.description = "<i> Bilateral Agreement between " + ni1
					+ " and " + ni2 + "</i><br><br><br>" + ni1 + this.ic1
					+ "<br><br>" + this.description;

	}

	/**
	 * Creates a MapEdge from the Agreement.
	 * 
	 * @return the MapEdge that represent the Agreement.
	 */
	public MapEdge getMapEdge() {
		this.normalize(this.type);
		MapVert p1 = this.i1.getMapVert();
		MapVert p2 = this.i2.getMapVert();
		String name = new String(this.type);
		String description = this.description;
		return new MapEdge(name, description, p1, p2, this.style);
	}
}
